#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from smtplib import SMTP, SMTPException
from email.mime.text import MIMEText
from email.header import Header

def main():
    sender = 'admin@qq.com'
    receivers = ['test@sina.com']
    mail_msg = """
    <p>Python 邮件发送测试...</p>
    <p><a href="https://blog.csdn.net/weixin_45444133?spm=1000.2115.3001.5343">这是一个链接</a></p>
    """
    # 创建文本内容
    message = MIMEText(mail_msg, 'html', 'utf-8')
    message['From'] = Header("admin", 'utf-8')
    message['To'] = Header("test", 'utf-8')
    message['Subject'] = Header('示范代码邮件', 'utf-8')

    try:
        smtper = SMTP('smtp.exmail.qq.com')
        smtper.login(sender, '授权码')
        smtper.sendmail(sender, receivers, message.as_string())
        print("邮件发送成功")
    except SMTPException:
        print("Error: 无法发送邮件")

if __name__=='__main__':
    main()